package cn.com.headfree.point.dao.impl;

import cn.com.headfree.entity.TPersonYearPoint;
import cn.com.headfree.point.dao.PersonYearPointDao;
import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import com.gta.edu.sdk.util.StringUtil;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;

@Repository("personYearPointDao")
public class PersonYearPointDaoImpl extends BaseDaoImpl<TPersonYearPoint> implements PersonYearPointDao {


    @Override
    public void saveInfo(TPersonYearPoint personYearPoint) {
        this.save(personYearPoint);
    }

    @Override
    public List<TPersonYearPoint> getLastYearPointByErpNo(String erpNo, Integer year) {
        ArrayList<Object> arrayList = new ArrayList<Object>();
        String sql = "select t.* from t_person_year_point t where t.del_sign = 0 " ;
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" AND t.erp_no= ? ");
        arrayList.add(erpNo);
        sqlBuilder.append(" AND t.year= ? ");
        arrayList.add(year);
        sqlBuilder.append(" order by create_time desc ");
        return this.findAllBySQL(TPersonYearPoint.class, sqlBuilder.toString(),null,false,arrayList.toArray());
    }

    @Override
    public List<TPersonYearPoint> getYearEffectByErpNo(String erpNo, Integer year) {
        ArrayList<Object> arrayList = new ArrayList<Object>();
        String sql = "select t.id,t.erp_no,t.rate_year as year from t_year_effect_info t where t.is_valid='0' and t.del_sign = 0 and t.perfor_grade='01' " ;
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" AND t.erp_no= ? ");
        arrayList.add(erpNo);
        sqlBuilder.append(" AND t.rate_year= ? ");
        arrayList.add(year);
        sqlBuilder.append(" order by create_time desc ");
        return this.findAllBySQL(TPersonYearPoint.class, sqlBuilder.toString(),null,false,arrayList.toArray());
    }

    @Override
    public List<TPersonYearPoint> getExpertTitleByErpNo(String erpNo, Integer year) {
        ArrayList<Object> arrayList = new ArrayList<Object>();
        String sql = "select t.id,t.erp_no,t.user_name from t_expert_title_info t where t.is_valid='0' and t.del_sign = 0 " ;
        StringBuilder sqlBuilder = new StringBuilder(sql);
        sqlBuilder.append(" AND t.erp_no= ? ");
        arrayList.add(erpNo);
        sqlBuilder.append(" AND t.acqu_time BETWEEN ? and ? ");
        arrayList.add(year + "-01-01");
        arrayList.add(year + "-12-31");
        sqlBuilder.append(" order by t.acqu_time desc ");
        return this.findAllBySQL(TPersonYearPoint.class, sqlBuilder.toString(),null,false,arrayList.toArray());
    }
}
